package com.iflytek.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iflytek.bean.Admin;
import com.iflytek.bean.Goods;
import com.iflytek.bean.StockInOrder;
import com.iflytek.bean.StockOutOrder;
import com.iflytek.mapper.AdminMapper;
import com.iflytek.mapper.GoodsMapper;
import com.iflytek.mapper.StockInOrderMapper;
import com.iflytek.mapper.StockOutOrderMapper;
import com.iflytek.service.AdminService;
import com.iflytek.service.StockInOrderService;
import com.iflytek.service.StockOutOrderService;
import com.iflytek.vo.StockOutOrderVO;

@Service
public class StockOutOrderServiceImpl implements StockOutOrderService{

	@Autowired
	private StockOutOrderMapper stockOutOrderMapper;
	@Autowired
	private GoodsMapper goodsMapper;

	@Override
	public List<StockOutOrder> selectByExample(Object object) {
		return stockOutOrderMapper.selectByExample(null);
	}

	@Override
	public void insertSelective(StockOutOrder stockOutOrder) {
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		stockOutOrder.setAgent(admin.getName());
		stockOutOrderMapper.insertSelective(stockOutOrder);
//		Goods good = goodsMapper.selectByPrimaryKey(stockOutOrder.getGoodsId());
//		good.setGoodsNum(good.getGoodsNum()-stockOutOrder.getGoodsNum());
//		goodsMapper.updateByPrimaryKeySelective(good);
	}

	@Override
	public void deleteByPrimaryKey(Integer orderId) {
		stockOutOrderMapper.deleteByPrimaryKey(orderId);
	}

	@Override
	public void updateByPrimaryKeySelective(StockOutOrder stockOutOrder) {
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		stockOutOrder.setAgent(admin.getName());
		stockOutOrderMapper.updateByPrimaryKeySelective(stockOutOrder);
	}

	@Override
	public List<StockOutOrderVO> selectByExample() {
		
		return stockOutOrderMapper.showAll();
	}
	
	
	

}
